MainFrameUtil={

    getParams:function(id){
	
    	var mainframe=top.Mainframe;
    	var dialog=mainframe.getDialogById(id);

		if(dialog){
			return dialog.params;
		}
		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				var dialog=mainframe.getDialogById(id);

				if(dialog){
					return dialog.params;
				}

				return null;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}*/
    
    },

    setDialogButtons:function(buttons,id){
	
    	var mainframe=top.Mainframe;
    	var dialog=mainframe.getDialogById(id);

		if(dialog){
			dialog.setButtons(buttons);
		}
		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				var dialog=mainframe.getDialogById(id);

				if(dialog){
					dialog.setButtons(buttons);
				}

				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}*/

    },
    setParams:function(params,id){
	
    	var mainframe=top.Mainframe;
    	var dialog=mainframe.getDialogById(id);

		if(dialog){
			dialog.params=params;
		}

		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				var dialog=mainframe.getDialogById(id);

				if(dialog){
					dialog.params=params;
				}

				return null;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}*/
	


	},
	openDialog:function(params){
		
		var mainframe = top.Mainframe; 

		var jscode="window";
		var fn = params['callback']||new Function();
		params['callback'] = function(){
			top.jQuery("#" + params['id']+'-window').draggable({ handle: ".row:eq(0)",containment:'window'});
			fn.apply(this,Array.prototype.slice.call(arguments));
		}
		mainframe.createDialog(params);
		/*for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				mainframe.createDialog(params);

				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}
	*/

    },
    closeDialog:function(id){
    
    	var mainframe = top.Mainframe;
    	if(mainframe){
			mainframe.closeDialog(id);
    	}
    	
		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				mainframe.closeDialog(id);

				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}*/
    
    },
    mainframe:function(){
        
		var mainframe = top.Mainframe;
		return !!mainframe;
		/*var jscode="window";
		
		for(var i=0;i<=10;i++){
			
		
			if(mainframe){
				
				return true;
			}
			
			if(i==10){
				return false;
			}
		
			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";
		
		}
	
		return false;*/
	},
    isOpen:function(id){
    	
    	var mainframe=top.Mainframe;
    	return mainframe && !!mainframe.exists(id);
		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(mainframe){
				
				var result=mainframe.exists(id);

				if(result===true){
					return true;
				}

			}
			
			var mainframeWindow=eval(jscode);
			
			mainframe=mainframeWindow.Mainframe;
			
			jscode+=".parent";

		}
		
		return false;*/

    },
    removeable:null,
    
    alert:function(params){
	
    	var dialog=top.alertObject;
    	
    	var buttons=[{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}];

		params.buttons=buttons;

		if(!params.icon){
			params.icon={color:"#ff8517",icon:"info-circle",size:"22px"};
		}

		dialog.openDialog(params);

		/*var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(dialog){
				
				var buttons=[{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}];

				params.buttons=buttons;

				if(!params.icon){
					params.icon={color:"#ff8517",icon:"info-circle",size:"22px"};
				}

				dialog.openDialog(params);

				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframe=eval(jscode);
			
			dialog=mainframe.alertObject;
			
			jscode+=".parent";

		}*/

    },
    confirm:function(params){
    	var opt = $.extend({
    		title:'确认提示',
    		body:'请确认?',
    		icon:{color:"#ff8517",icon:"exclamation-circle",size:"22px"},
    		buttons:[{text:'取消',icon:'close',bgcolor:"#cccccc",type:"cancel"},{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}]
    	},params);
		var dialog=top.alertObject;
		dialog.openDialog(opt);
		
		/*var jscode="window";
		
		for(var i=0;i<=10;i++){
			
		
			if(dialog){
				
				var buttons=[{text:'取消',icon:'close',bgcolor:"#cccccc",type:"cancel"},{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}];
		
				params.buttons=buttons;
				
				if(!params.icon){
					params.icon={color:"#ff8517",icon:"exclamation-circle",size:"22px"};
				}
		
				dialog.openDialog(params);
		
				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}
		
			var mainframe=eval(jscode);
			
			dialog=mainframe.alertObject;
			
			jscode+=".parent";
		
		}*/
	
	},
    customAlert:function(params){
    	
		var dialog=top.alertObject;
		if(!params.buttons){
			
			var buttons=[{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}];
			
			params.buttons=buttons;
		}
		
		if(!params.icon){
			params.icon={color:"#ff8517",icon:"exclamation-circle",size:"22px"};
		}

		dialog.openDialog(params);
		
		/*var jscode="window";
		
		for(var i=0;i<=10;i++){
			
		
			if(dialog){
				
				if(!params.buttons){
					
					var buttons=[{text:'确定',icon:'check',bgcolor:"#337ab7",type:"ok"}];
					
					params.buttons=buttons;
				}
				
				if(!params.icon){
					params.icon={color:"#ff8517",icon:"exclamation-circle",size:"22px"};
				}
		
				dialog.openDialog(params);
		
				break;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}
		
			var mainframe=eval(jscode);
			
			dialog=mainframe.alertObject;
			
			jscode+=".parent";
		
		}*/
		
	},
	openTabPage:function(tabid, url, name,reload){
		if(typeof top.CreateDiv === 'function'){
			top.CreateDiv.apply(this,Array.prototype.slice.call(arguments));
		}
		/*var func=null;

		var jscode="window";

		for(var i=0;i<=10;i++){
			

			if(func){
				
			    func(tabid, url, name,reload);

				return null;
			}
			
			if(i==10){
				console.log("寻找10层后仍未找到可弹框窗体");
			}

			var mainframeWindow=eval(jscode);
			
			func=mainframeWindow.CreateDiv;
			
			jscode+=".parent";

		}*/
	
	}
}
function getBasePath(){
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPath = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    var basePath=localhostPath+projectName+"/";
    return basePath;
};
//修改函数作用域为顶层窗口,并添加tab页窗口到MainframeUtil
(function(){
	var _fns = ['CreateDiv','RemoveDiv','CreateSubDiv','resetTabDiv','removeFromTabArray','showTabs','moveForward','moveBackward','showOrHiddenPagination'];
	for(var i = 0,len = _fns.length;i<len;i++){
		var fnName = _fns[i];
		window[fnName] = MainFrameUtil[fnName] = top[fnName];
	}
})();